﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using AutoMapper;
using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.pressions;



namespace MyMES.Writer.API.Application.CommendHandlers.Pressions
{
    public class UpdatePressionHandler : IRequestHandler<UpdateCommand, APIResult<Pression>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<Pression> repository;

        public UpdatePressionHandler(IMapper mapper, IBaseRepository<Pression> repository)
        {
            this.mapper = mapper;
            this.repository = repository;
        }
        public async Task<APIResult<Pression>> Handle(UpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<Pression> result = new APIResult<Pression>();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var pro = mapper.Map<Pression>(request);
            string sql = "update Pression set PressName=@PressName,IsDlete=@IsDlete where PressId=@PressId";
            await repository.Update(pro, sql);
            return result;
        }
    }
}
